<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
	<head>
		<title>JavaScript unit test file</title>
		<meta http-equiv="content-type" content="text/html; charset=utf-8" />
		<link rel="stylesheet" href="unittest.css" type="text/css" />
		<script src="jsunittest.js" type="text/javascript"></script>
		<script src="jscontext.js" type="text/javascript"></script>

		<script src="../zen_settings.js" type="text/javascript"></script>
		<script src="../my_zen_settings.js" type="text/javascript"></script>
		<script src="../lib/zen_coding.js" type="text/javascript"></script>
	</head>
	<body>
		<div id="content">
			<div id="header">
				<h1>Zen Coding</h1>
			</div>
			<!-- Log output (one per Runner, via {testLog: "testlog"} option)-->
			<div id="testlog"></div>

			<!-- Put sample/test html here -->
			<div id="sample"></div>
		</div>
		<script type="text/javascript">
			zen_coding.setupProfile('demo', {tag_case: 'upper', attr_case: 'upper'});
			
			function expandAbbr(abbr, type, profile) {
				return zen_coding.expandAbbreviation(abbr, type, profile);
			}
			
//			console.log(zen_settings);
			
//			console.log(expandAbbr('html:xs>ul#nav>li.item$*4', 'html', 'xhtml'));
			
			new Test.Unit.Runner({
				"test '+' operator": function(){ with (this) {
					assertEqual('<p></p><p></p>', expandAbbr('p+p'));
					assertEqual('<p></p><p></p>', expandAbbr('p+P'));
					assertEqual('<p class="name"></p><p></p><p></p>', expandAbbr('p.name+p+p'));
				 }},
				"test '>' operator": function(){ with (this) {
					assertEqual('<p><em></em></p>', expandAbbr('p>em'));
					assertEqual('<p class="hello"><em class="world"><span></span></em></p>', expandAbbr('p.hello>em.world>span'));
				 }},
				"test attributes": function(){ with (this) {
					assertEqual('<p class="name"></p>', expandAbbr('p.name'));
					assertEqual('<p class="one two three"></p>', expandAbbr('p.one.two.three'));
					assertEqual('<p class="one-two three"></p>', expandAbbr('p.one-two.three'));
					assertEqual('<p class="one two-three"></p>', expandAbbr('p.one.two-three'));
					assertEqual('<p class="one_two-three"></p>', expandAbbr('p.one_two-three'));
					assertEqual('<p id="myid"></p>', expandAbbr('p#myid'));
					assertEqual('<p id="myid" class="name_with-dash32 otherclass"></p>', expandAbbr('p#myid.name_with-dash32.otherclass'));
					assertEqual('<span class="one two three"></span>', expandAbbr('span.one.two.three'));
				 }},
				 
				 "test expandos":  function(){ with (this) {
					assertEqual('<dl><dt></dt><dd></dd></dl>', expandAbbr('dl+'));
					assertEqual('<div></div><div><dl><dt></dt><dd></dd></dl></div>', expandAbbr('div+div>dl+'));
				 }},
				 
				 "test counters":  function(){ with (this) {
					assertEqual('<ul id="nav"><li class="item1"></li><li class="item2"></li><li class="item3"></li></ul>', expandAbbr('ul#nav>li.item$*3'));
				 }},
				 
				 "test user-defined settings":  function(){ with (this) {
					assertEqual('<scr' + 'ipt type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></scr' + 'ipt>', expandAbbr('jq'));
					assertEqual('<div id="demo"></div>', expandAbbr('demo'));
				 }},
				 
				 "test short tags":  function(){ with (this) {
					assertEqual('<blockquote><p></p></blockquote>', expandAbbr('bq>p'));
				 }},
				 
				 "test tag match": function(){ with (this) {
					assertEqual('bq>p', zen_coding.extractAbbreviation('<div>bq>p'));
					assertEqual('bq>p', zen_coding.extractAbbreviation('<div class="hello" id="world">bq>p'));
					assertEqual('bq>p', zen_coding.extractAbbreviation('<div some:extention="value">bq>p'));
				 }},
				 
				 "test misc patterns": function() {with (this) {
				 	assertEqual('<scr' + 'ipt type="text/javascript"></scr' + 'ipt>', expandAbbr('script'));
				 	assertEqual('<scr' + 'ipt type="text/javascript" src=""></scr' + 'ipt>', expandAbbr('script:src'));
				 	assertEqual('<img src="" alt="" />', expandAbbr('img'));
				 	assertEqual('<input type="checkbox" name="" id="" />', expandAbbr('input:c'));
				 	assertEqual('<some:elem></some:elem>', expandAbbr('some:elem'));
				 	assertEqual('<li id="id1" class="class1"></li><li id="id2" class="class2"></li><li id="id3" class="class3"></li>', expandAbbr('li#id$.class$*3'));
				 	assertEqual('<select name="" id="test"></select>', expandAbbr('select#test'));
				 }},
				 
				 "test XSL": function(){ with (this) {
					assertEqual('<xsl:template match="" mode=""></xsl:template>', expandAbbr('tmatch', 'xsl'));
					assertEqual('<xsl:choose><xsl:when test=""></xsl:when><xsl:otherwise></xsl:otherwise></xsl:choose>', expandAbbr('choose+', 'xsl'));
					assertEqual('<xsl:variable><div></div><p></p></xsl:variable>', expandAbbr('xsl:variable>div+p', 'xsl'));
					assertEqual('<xsl:variable name=""><div></div><p></p></xsl:variable>', expandAbbr('var>div+p', 'xsl'));
					assertEqual('<xsl:apply-templates select="" mode="" />', expandAbbr('ap', 'xsl'));
				 }},
				 
				 "test CSS": function(){ with (this) {
					assertEqual('@import url(|);', expandAbbr('@i', 'css'));
					assertEqual('!important', expandAbbr('!', 'css'));
					assertEqual('position:static;', expandAbbr('pos:s', 'css'));
					assertEqual('text-indent:-9999px;', expandAbbr('ti:-', 'css'));
					assertEqual('border-bottom:1px solid #000;', expandAbbr('bdb+', 'css'));
				 }},
				 
				 "test inheritance": function(){ with (this) {
					assertEqual('<a href=""></a>', expandAbbr('a', 'xsl'));
					assertEqual('<div id="demo"></div>', expandAbbr('demo', 'xsl'));
				 }},
				 
				 "test non-existed types": function(){ with (this) {
					assertEqual('<a></a>', expandAbbr('a', 'foo'));
					assertEqual('<bq><p></p></bq>', expandAbbr('bq>p', 'foo'));
				 }},
				 
				 "test tag hit": function(){ with (this) {
					assertEqual(true, zen_coding.isInsideTag('hello<div>world', 7));
					assertEqual(true, zen_coding.isInsideTag('hello<br />world', 7));
					assertEqual(true, zen_coding.isInsideTag('hello</p>world', 7));
					assertEqual(false, zen_coding.isInsideTag('hello<div>world', 10));
					assertEqual(false, zen_coding.isInsideTag('hello<div>world', 1));
				 }},
				 
				 "test formatting": function(){ with (this) {
					assertEqual('<blockquote>\n\t<p>|</p>\n</blockquote>', expandAbbr('bq>p', 'html', 'xhtml'));
					assertEqual('<blockquote>|</blockquote>\n<p>|</p>', expandAbbr('bq+p', 'html', 'xhtml'));
					assertEqual('<img src="|" alt="|" />\n<p>|</p>', expandAbbr('img+p', 'html', 'xhtml'));
					assertEqual('<xsl:variable name="|" select="|"/>', expandAbbr('vare', 'xsl', 'xml'));
					assertEqual('<xsl:variable name="|" select="|"/>\n<p>\n\t|\n</p>', expandAbbr('vare+p', 'xsl', 'xml'));
				 }},
				 
			});
		</script>
	</body>
</html>
